--不退之旗
local butuizhiqi = fk.CreateSkill {
    name = "mcdh_butuizhiqi"
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

butuizhiqi:addEffect(fk.GameStart,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self)
    end,
    on_cost = function(self, event, target, player, data)
            return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player, "@@mcdh_butuizhiqi-mark", 1)
    end
})

butuizhiqi:addEffect(fk.DrawInitialCards,{
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) then
                return target == player and player:getMark("@@mcdh_butuizhiqi-mark") ~= 0
        end
    end,
    on_cost = function(self, event, target, player, data)
            local room = player.room
            local targets = room:askToChoosePlayers(player,{targets=table.filter(room:getAlivePlayers(), function(p) return p:getMark("@@mcdh_butuizhiqi-mark") ~= 0 end),skill_name=self.name,min_num=1,max_num=1,prompt="#butuizhiqi-choose"})
            if #targets > 0 then
                event:setCostData(self,targets[1])
                return true
            end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(event:getCostData(self), "@@mcdh_butuizhiqi-mark", 0)
        return true
    end
})

butuizhiqi:addEffect(fk.DrawNCards,{
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) then
            return target:getMark("@@mcdh_butuizhiqi-mark") ~= 0
        end
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        data.n = data.n + 1
    end
})

butuizhiqi:addEffect('maxcards',{
    fixed_func = function(self, player)
        if player:getMark("@@mcdh_butuizhiqi-mark") ~= 0 and
                table.find(
                        Fk:currentRoom().alive_players,
                        function(p)
                            return p:hasSkill("mcdh_butuizhiqi")
                        end
                ) then
            return player.maxHp
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_butuizhiqi"] = "不退之旗",
    [":mcdh_butuizhiqi"] = "游戏开始时，你获得一枚「军旗」标记。拥有「军旗」标记的角色，摸牌阶段多摸一张，手牌上限等于体力上限。" ..
        "当你受到伤害时，若你有「军旗」，你可以移去一名角色的一枚「军旗」，然后防止此伤害。",
    ["@@mcdh_butuizhiqi-mark"] = "军旗",
    ["#butuizhiqi-choose"] = "不退之旗:移去一名角色的一枚「军旗」"
}

return butuizhiqi